﻿using System;
using System.Drawing;

namespace geometry
{
    public class Rectangle
    {
        public int width;
        public int height;
        public Rectangle(int a,int b)//输入长与宽创建长方形
        {
            this.height = a;
            this.width = b;
        }
        public int Area()//计算面积
        {
            return this.height * this.width;
        }
        public bool Valid()//判断是否合法
        {
            return this.height > 0 && this.width > 0;//长与宽均大于0即为合法
        }
    }//长方形类

    public class Square
    {
        public int a;
        public Square(int a)
        {
            this.a = a;
        }
        public int Area()
        {
            return this.a * this.a;
        }
        public bool Valid()
        {
            return this.a > 0;
        }
    }//正方形类，结构同上

    public class Circle
    {
        public int r;
        public Circle(int a)
        {
            this.r = a;
        }
        public double Area()
        {
            return Math.PI * this.r * this.r;
        }
        public bool Valid()
        {
            return this.r > 0;
        }
    }//圆形类，结构同上

    class Geometry
    {
        static void Main(string[] args)
        {
            Random random = new Random();//创建随机数，随机生成图形
            double sum = 0;//面积总和
            for(int i=1;i<11;i++)
            {
                int shape= random.Next(1,4);
                switch(shape)
                {
                    case 1:
                        int a = random.Next(1,100);
                        int b = random.Next(1,100);//随机生成长与宽，为1-100的整形随机数
                        Rectangle rec = new Rectangle(a, b);
                        sum += rec.Area();
                        Console.WriteLine($"{i}.生成图形：长方形");
                        Console.WriteLine($"边长：{a} {b} ");
                        Console.WriteLine($"面积：{rec.Area()}");//输出生成图形
                        break;
                    case 2:
                        int side = random.Next(1, 100);
                        Square sqe = new Square(side);
                        sum += sqe.Area();
                        Console.WriteLine($"{i}.生成图形：正方形");
                        Console.WriteLine($"边长：{side} ");
                        Console.WriteLine($"面积：{sqe.Area()}");//同上
                        break;
                    case 3:
                        int r = random.Next(1, 100);
                        Circle cir = new Circle(r);
                        sum += cir.Area();
                        Console.WriteLine($"{i}.生成图形：圆形");
                        Console.WriteLine($"边长：{r} ");
                        Console.WriteLine($"面积：{cir.Area()}");//同上
                        break;
                }
                Console.WriteLine();//换行
            }
            Console.WriteLine($"总面积为：{sum}");
            Console.ReadLine();
        }
    }
}